package com.minhang.utils.result;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * @author rookie
 */
public class ResPage {


    public static PageInfo getPageInfo(Integer currentPage,
                                       Integer pageSize,
                                       List weeks) {
        //创建Page类
        Page page = new Page(currentPage, pageSize);
        //为Page类中的total属性赋值
        int total = weeks.size();
        page.setTotal(total);
        //计算当前需要显示的数据下标起始值
        int startIndex = (currentPage - 1) * pageSize;

        int endIndex = Math.min(startIndex + pageSize, total);
        //从链表中截取需要显示的子链表，并加入到Page
        if (startIndex <= total) {
            page.addAll(weeks.subList(startIndex, endIndex));
        }
        //以Page创建PageInfo
        PageInfo pageInfo = new PageInfo<>(page);

        return pageInfo;
    }
}
